# Build recipe for libgpg-error
#
# Copyright 2016,2018 Mateus P. Rodrigues <mprodrigues@dragora.org>.
#
# This recipe is free software, under the terms of the Apache License 2.0

program=libgpg-error
version=1.27
release=1

description="
Libgpg-error is a small library that defines common error values for
all GnuPG components. Among these are GPG, GPGSM, GPGME, GPG-Agent,
libgcrypt, Libksba, DirMngr, Pinentry, SmartCard Daemon and possibly
more in the future.
"

homepage=http://www.gnupg.org/related_software/libgpg-error/index.html
license="GPLv2, LGPLv2"

tarname=${program}-${version}.tar.bz2

# Remote source(s)
fetch=https://www.gnupg.org/ftp/gcrypt/libgpg-error/$tarname

# Source documentation
docs="ABOUT-NLS AUTHORS COPYING* NEWS README THANKS VERSION"
docsdir="${docdir}/${program}-${version}"

build() {
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    ./configure CFLAGS="$QICFLAGS" LDFLAGS="$QILDFLAGS" \
     $configure_args \
     --libdir=/usr/lib${libSuffix} \
     --infodir=$infodir \
     --mandir=$mandir \
     --docdir=$docdir \
     --build="$(cc -dumpmachine)"

    make -j${jobs} V=1
    make -j${jobs} DESTDIR="$destdir" install

    # Compress info documents deleting index file for the package
    if test -d "${destdir}/$infodir"
    then
        rm -f "${destdir}/${infodir}/dir"
        lzip -9 "${destdir}/${infodir}"/*
    fi

    # Compress and link man pages (if needed)
    if test -d "${destdir}/$mandir"
    then
        (
            cd "${destdir}/$mandir"
            find . -type f -exec lzip -9 '{}' +
            find . -type l | while read -r file
            do
                ln -sf "$(readlink -- "$file").lz" "${file}.lz"
                rm -- "$file"
            done
        )
    fi

    # Copy documentation
    mkdir -p "${destdir}${docsdir}"
    cp -p $docs "${destdir}${docsdir}"
}
